//
//  KSDNavigationController.m
//  KSuodun
//
//  Created by DwZeng on 2022/7/18.
//

#import "KSDNavigationController.h"
#import "UINavigationBar+ZCLNavigationBar.h"

@interface KSDNavigationController ()<UINavigationControllerDelegate, UIGestureRecognizerDelegate,UINavigationBarDelegate>

@end

@implementation KSDNavigationController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationBarHidden = YES;
}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
    [UITabBar appearance].translucent = YES;
    return [super popViewControllerAnimated:animated];
}
- (NSArray<UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    [UITabBar appearance].translucent = YES;
    return [super popToViewController:viewController animated:animated];
}
- (NSArray<UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated
{
    [UITabBar appearance].translucent = YES;
    return [super popToRootViewControllerAnimated:animated];
}


/**
 *  重写这个方法目的：能够拦截所有push进来的控制器
 *
 *  @param viewController 即将push进来的控制器
 */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) { // 这时push进来的控制器viewController，不是第一个子控制器（不是根控制器）
        /* 自动显示和隐藏tabbar */
        viewController.hidesBottomBarWhenPushed = YES;
        [UITabBar appearance].translucent = NO;
        
    }
    [super pushViewController:viewController animated:animated];
}




//- (void)navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item {
//    //只有一个控制器的时候禁止手势，防止卡死现象
//    if (self.childViewControllers.count == 1) {
//        if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//            self.interactivePopGestureRecognizer.enabled = NO;
//        }
//    }
//}
//
//- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPushItem:(UINavigationItem *)item {
//    //只有一个控制器的时候禁止手势，防止卡死现象
//    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//        self.interactivePopGestureRecognizer.enabled = NO;
//    }
//    if (self.childViewControllers.count > 1) {
//        if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//            self.interactivePopGestureRecognizer.enabled = YES;
//        }
//    }
//    return YES;
//}
@end
